package com.yumeng.webapp.shiro.common;

import com.yumeng.common.api.ApiCode;
import com.yumeng.common.exception.DemoException;
import com.yumeng.framework.core.mvc.BaseGlobalExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;

/**
 * 统一异常处理
 *
 * @author wxd
 * @date 2025/9/20 11:04
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler extends BaseGlobalExceptionHandler {

    @ExceptionHandler(DemoException.class)
    public final ResponseEntity<Object> handleDemoException(DemoException ex, WebRequest request) throws Exception{
        HttpStatus status = HttpStatus.OK;
        ApiCode apiCode = ApiCode.BUSINESS_EXCEPTION;
        HttpHeaders headers = new HttpHeaders();
        return doHandleException(ex, null, headers, status, request, apiCode, ex.getMessage());
    }

}
